<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=building-width, initial-scale=1, maximum-scale=1">
    <% include("/templates/common/header.html"){} %>
    <!-- jqgrid-->
    <link href="${ctxPath!}/css/bootstrap.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxPath!}/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="${ctxPath!}/jqgrid/jqgrid.css" rel="stylesheet">
    <style>
        .ui-jqgrid-btable tbody tr td{
            vertical-align: middle!important;
        }
    </style>
</head>
<body>
    <div class="content-search">
        <form id="search" class="layui-form layui-form-pane" lay-filter="form">
            <div class="layui-inline" style="margin-left: 10px;">
                <div class="layui-input-inline">
                    <input type="text" id="keyword" autocomplete="off" class="layui-input" placeholder="请输入关键字" onchange="search()">
                </div>
                <div class="layui-inline">
                    <atom:auth type="button" perm="sys:building:edit"  iconText="&#xe615;" onclick="return search();" text=" 搜索"/>
                    <atom:auth type="button" perm="sys:building:edit" iconText="&#xe654;" onclick="return add();" text="添加楼栋"/>
                </div>
            </div>
        </form>
    </div>
        <!-- 内容主体区域 -->
    <div style="padding: 2px;">
        <div class="jqGrid_wrapper">
            <table id="table"></table>
            <div id="pager" ></div>
        </div>
    </div>
</div>
<script src="${ctxPath!}/jquery/jquery.min.js?v=2.2.4"></script>
<script src="${ctxPath!}/jquery/jquery.form.js?v=3.50.0"></script>
<script src="${ctxPath!}/jqgrid/i18n/grid.locale-cnffe4.js?0820"></script>
<script src="${ctxPath!}/jqgrid/jquery.jqGrid.minffe4.js?0820"></script>
<script src="${ctxPath!}/jqgrid/frozen.js?v=1.0.1"></script>
<script src="${ctxPath!}/jqgrid/myjqGrid.js"></script>
<script src="${ctxPath!}/layui/layui.js"></script>
<script>

    layui.use('form', function(){
    });

    var colNames = ["楼栋名称" ,"设备账号","设备ID1","设备ID2","是否为有人云设备","是否启用预测功能","操作"];
    var colModel = [{
        name : "name",
        index : "name",
        sortable : false,
        editable : false,
        width : 80,
        align : "center"
    },{
        name : "account",
        index : "account",
        sortable : false,
        editable : false,
        width : 40,
        align : "center"
    },{
        name : "deviceId1",
        index : "deviceId1",
        editable : false,
        sortable : false,
        width : 85,
        align : "center"
    },{
        name : "deviceId2",
        index : "deviceId2",
        editable : false,
        sortable : false,
        width : 85,
        align : "center"
    },{
        name : "cloud",
        index : "cloud",
        editable : false,
        sortable : false,

        width : 70,
        align : "center",
        formatter : function(cellvalue, options, rowdata){
            if(rowdata.cloud){
                return "是";
            }else {
                return "否";
            }
        }
    },{
        name : "forecast",
        index : "forecast",
        editable : false,
        sortable : false,

        width : 70,
        align : "center",
        formatter : function(cellvalue, options, rowdata){
            if(rowdata.forecast){
                return "是";
            }else {
                return "否";
            }
        }
    },
//        {
//        name : "connect",
//        index : "connect",
//        editable : false,
//        width : 50,
//        align : "center",
//        formatter : function(cellvalue, options, rowdata){
//            if(rowdata.connect){
//                return "<div class='layui-bg-blue'>已连接</div>";
//            }else {
//                return "<div class='layui-bg-red'>未连接</div>";
//            }
//        }
//    },
        {
        name : "action",
        index : "action",
        width : 150,
        title:false,
        editable:true,
        align : "center",
        formatter : function(cellvalue, options, rowdata){
            var html ="";
//            if(!rowdata.connect){
//                html+='<atom:auth type="button" perm="sys:building:edit" extClass="btn-connect layui-bg-orange" iconText="&#xe6c6;" dataId="' + rowdata.id + '" text="连接有人云" />';
//            }
            html+=
                '<atom:auth type="button" perm="sys:building:edit" extClass="btn-edit" iconText="&#xe642;" dataId="' + rowdata.id + '" text="编辑楼栋" />'+
                    '<atom:auth type="button" perm="sys:building:delete" extClass="btn-del layui-bg-red" iconText="&#xe640;" dataId="' + rowdata.id + '" text="删除楼栋" />';
            return html;
        }
    }];

    var myJqGrid = null;
    $(document).ready(function () {
        myJqGrid = new MyJqGrid({
            jqGrid_id: 'table',
            data: "${ctxPath!}/sys/building/list.json",
            isSubGrid: false,
            autowidth: true,
            shrinkToFit: true,
            autoScroll: true,
            colNames: colNames,
            colModel: colModel
        })
    });


    function search(){
        myJqGrid.reloadGrid({'keyword':$("#keyword").val()});
        return false;
    }

    function add() {
        layer.open({
            title: '添加楼栋',
            type: 2,
            area: ['750px', '550px'],
            content: '${ctxPath!}/sys/building/edit'
        });
        return false;
    }

    $(function(){

        $(document).on("click", ".btn-edit", function (e) {
            layer.open({
                title: '编辑楼栋',
                type: 2,
                area: ['750px', '550px'],
                content: '${ctxPath!}/sys/building/edit?id='+$(this).data("id")
            });
        });

        $(document).on("click", ".btn-del", function (e) {
            var id = $(this).data("id");
            layer.confirm('确定删除该楼栋吗？', {
                icon: 3,
                btn: ['确定','取消'] //按钮
            }, function(){ //确定
                var params = {"id":id};
                console.log(id);
                $.post("${ctxPath!}/sys/building/delete", params, function(data){
                    if(data.status == 200){
                        layer.alert(data.msg, {
                            icon: 1,
                            skin: 'layer-ext-moon'
                        },function () {
                            search();
                            layer.closeAll();
                        });
                    }else{
                        layer.alert(data.msg, {
                            icon: 2,
                            skin: 'layer-ext-moon'
                        });
                    }
                });
            }, function(){ //取消
            });
        });
    });

</script>
</body>
</html>